'''
Created on Apr 28, 2010

@author: william
'''

import ConfigParser
import sys

# Loads the configuration file into memory.
def load(arg):
        network_options = ['poll_interval', # Available network config options 
                           'port', ] 
        options = {}
        
        config = ConfigParser.RawConfigParser()
        # Using readfp allows us to catch an IOError exception in case the file does not
        # exist. An exception handler should be added to make the error a bit friendlier
        # and to exit the agent
        try:
            config.readfp(open(arg))
        except IOError: # If file doesn't exist, print an error and exits.
            print 'Cannot open "', arg, '"'
            sys.exit()

        # Tries to read each line in the network section of the configuration.
        for line in network_options:
            try:
                options[line] = config.getint('Network', line)
            except:
                print 'Error reading configuration.'
                sys.exit()

        return options

    
    